<?php
namespace Hive\Mission;
/**
 * Customizing Point Hander Object for Mission
 * This object is an instance that can be called to 
 * load custom behavior.
 * 
 * @package Hive\Mission
 * @author Xavier VILAIN
 * 
 */
use Fox\Generator;

class Customizing {
	
	/**
	 * 
	 * Ressource Summary Page Id
	 * @var string
	 */
	const SUMMARY_PAGE = 'm-summary-page';
	
	/**
	 * Singleton instance
	 *
	 * @var \Fox\Html\Steppers
	 */
	private static $_instance;
	
	/**
	 * Candidate Main Api screen
	 * @var string
	 */
	public $mainScreen = 'mission-main';
	
	/**
	 * 
	 * Enter description here ...
	 */
	public function __construct() {
		
	}
	
	/**
	 * Retrieve singleton instance
	 *
	 * @return Customizing
	 */
	public static function instance()
	{
		if (null === self::$_instance) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	
	/**
	 * This method will be used to find what should be the 
	 * contact default displayed page
	 * 
	 * @param array $params List of additionnal params
	 * @return Fox\Generator
	 */
	public function defaultSummaryPage($params = null) {
		$summaryPageId = self::SUMMARY_PAGE;

		$module = 'missions';
		$action = 'process';
		$subact = null;
		//@TODO add a customizing point here to select default user screen
		if(isset($_SESSION[$summaryPageId])) {
			$module = !empty($_SESSION[$summaryPageId]['mod']) ? $_SESSION[$summaryPageId]['mod'] : 'missions';
			$action = !empty($_SESSION[$summaryPageId]['act']) ? $_SESSION[$summaryPageId]['act'] : 'process';
			$subact = !empty($_SESSION[$summaryPageId]['sac']) ? $_SESSION[$summaryPageId]['sac'] : null;
		}
		$url = Generator::url($module,$action,$subact,$params);
		$_SESSION[$summaryPageId] = array('mod' => $module,'act'=> $action,'sac' => $subact);
		
		return array($url,$action);
	}
	
	/**
	 * 
	 * Save current page for futher display
	 * @param array $params
	 * @return Customizing
	 */
	public function trackSummaryPage($params = null) {
		if(isset($params['mod'])) {
			$_SESSION[self::SUMMARY_PAGE] = array(
				'mod' => $params['mod'],
				'act' => isset($params['act']) ? $params['act'] : null,
				'sac' => isset($params['sac']) ? $params['sac'] : null
			);
		}
		return $this;
	}
}